package com.flyou.ccnucenter.adapter;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.domain.LostComments;
import com.flyou.ccnucenter.utils.ColorPhrase;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * ============================================================
 * 项目名称：HenuCenterPro
 * 包名称：com.flyou.henucenter.adapter
 * 文件名：LostFoundDetialCommentAdapter
 * 类描述：
 * 创建人：flyou
 * 邮箱：fangjaylong@gmail.com
 * 创建时间：2016/1/12 9:33
 * 修改备注：
 * 版本：@version  V1.0
 * ============================================================
 */
public class LostFoundDetialCommentAdapter extends SimpleBaseAdapter {
    private OnReplyItemClickListener mListener;

    public LostFoundDetialCommentAdapter(Context context, List<LostComments> data, OnReplyItemClickListener listener) {
        super(context, data);
        this.mListener = listener;
    }

    @Override
    public int getItemResource() {
        return R.layout.view_lostfound_comment_item;
    }

    @Override
    public View getItemView(final int position, View convertView, ViewHolder holder) {
        LostComments lostComment;
        Object item = getItem(position);
        lostComment = (LostComments) item;
        SimpleDraweeView userHeadImage = (SimpleDraweeView) holder.getView(R.id.user_header_bg);
        TextView floor_num = (TextView) holder.getView(R.id.tv_floor_num);
        TextView commentTime = (TextView) holder.getView(R.id.tv_comment_time);
        TextView content = (TextView) holder.getView(R.id.tv_content);
        TextView userName = (TextView) holder.getView(R.id.tv_userName);
        TextView replayFloor = (TextView) holder.getView(R.id.tv_reply_post);
        userHeadImage.setImageURI(Uri.parse(lostComment.getMyUser().getHeadImage()));
        floor_num.setText((position + 1) + " 楼");
        userName.setText(lostComment.getMyUser().getUsername());
        if (TextUtils.isEmpty(lostComment.getCreatedAt())) {
            String data = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            commentTime.setText(data);
        } else {
            commentTime.setText(lostComment.getCreatedAt());
        }


        CharSequence formatted1 = ColorPhrase.from(lostComment.getComment())
                .withSeparator("{}")
                .innerColor(0xff5cabdf)
                .outerColor(0xFF000000)
                .format();
        content.setText(formatted1);

        replayFloor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onReplyItemClick(position);
            }
        });

        return convertView;
    }

    public interface OnReplyItemClickListener {

        public void onReplyItemClick(int positoion);


    }


}
